// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2005-5-23

#ifndef __AUTOHANDLE_H_COMMON_GUARD__
#define __AUTOHANDLE_H_COMMON_GUARD__

#pragma once

namespace JoyGuard
{

//##ModelId=44C4B60E0234
class AutoHandle
{
protected:
	//##ModelId=44C4B60E0242
    HANDLE m_handle;
public:
	//##ModelId=44C4B60E0251
    AutoHandle()
    {
        m_handle = NULL;
    }
	//##ModelId=44C4B60E0252
    AutoHandle(HANDLE h)
    {
        m_handle = h;
    }
	//##ModelId=44C4B60E0254
    ~AutoHandle()
    {
        if(m_handle != NULL && m_handle != INVALID_HANDLE_VALUE)
        {
            ::CloseHandle(m_handle);
        }
    }

	//##ModelId=44C4B60E0255
    AutoHandle& operator = (HANDLE h)
    {
        m_handle = h;
        return *this;
    }

	//##ModelId=44C4B60E0262
    bool operator == (HANDLE h) const
    {
        return m_handle == h;
    }
	//##ModelId=44C4B60E0265
    bool operator != (HANDLE h) const
    {
        return m_handle != h;
    }

	//##ModelId=44C4B60E0268
    operator HANDLE () const
    {
        return m_handle;
    }
};


} // namespace JoyGuard

#endif  // __AUTOHANDLE_H_COMMON_GUARD__
